package de.sonntagsfarben.display
{
	import flash.events.Event;

	import de.sonntagsfarben.display.CoreSprite;

	import flash.events.MouseEvent;

	/**
	 * @author Soenke Kluth <kluth@sonntagsfarben.de>
	 */
	public class InteractiveSprite extends CoreSprite
	{
		public function InteractiveSprite()
		{
			super();
			buttonMode = true;
		}


		override protected function onAddedToStage(event:Event):void
		{
			addEventListener(MouseEvent.MOUSE_OVER, onMouseOver, false, 0, true);
			addEventListener(MouseEvent.MOUSE_OUT, onMouseOut, false, 0, true);
			addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
			addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown, false, 0, true);
			addEventListener(MouseEvent.MOUSE_UP, onMouseUp, false, 0, true);
			addEventListener(MouseEvent.ROLL_OVER, onRollOver, false, 0, true);
			addEventListener(MouseEvent.ROLL_OUT, onRollOut, false, 0, true);
			super.onAddedToStage(event);
		}


		override protected function onRemovedFromStage(event:Event):void
		{
			removeEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			removeEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
			removeEventListener(MouseEvent.CLICK, onClick);
			removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
			removeEventListener(MouseEvent.ROLL_OVER, onRollOver);
			removeEventListener(MouseEvent.ROLL_OUT, onRollOut);
			super.onRemovedFromStage(event);
		}


		protected function onMouseOver(event:MouseEvent):void
		{
		}


		protected function onMouseOut(event:MouseEvent):void
		{
		}


		protected function onClick(event:MouseEvent):void
		{
		}


		protected function onMouseDown(event:MouseEvent):void
		{
		}


		protected function onMouseUp(event:MouseEvent):void
		{
		}


		protected function onRollOver(event:MouseEvent):void
		{
		}


		protected function onRollOut(event:MouseEvent):void
		{
		}


		override public function destroy():void
		{
			if (!destroyed)
			{
				onRemovedFromStage(new Event(Event.REMOVED_FROM_STAGE));
				super.destroy();
			}
		}
	}
}
